// System 

function System() {
	// NOOP
}

System.log = function(msg) {
	var esc = true;
	if (arguments.length > 1) esc = arguments[1];
	if (esc) jQuery('#_console').append(jQuery('<div></div>').text(msg));
	else jQuery('#_console').append(jQuery('<div></div>').html(msg));
}

function Exception(message) {
	this.message = message || '';
}

// Reader

function Reader(file) {
	this.pos = 0;
	this.buffer = jQuery.ajax({
		url: file,
		dataType: 'text',
		async: false
	}).responseText;
}

Reader.EOF = -1;

Reader.prototype.read = function() {
	if (this.pos == this.buffer.length) return Reader.EOF;
	return this.buffer.charCodeAt(this.pos++);
};

// Writer

function Writer(file) {
	System.log(file + ':\n\n');
	this.buffer = '';
}

Writer.prototype.write = function(str) {
	this.buffer += str;
};

Writer.prototype.writeln = function(str) {
	this.buffer += (str == undefined ? '' : str) + '\n';
};

Writer.prototype.close = function(str) {
	System.log(this.buffer);
};

// exceptions

function EndOfFileException(message) {
	Exception.call(this,message);
}

EndOfFileException.prototype = new Exception();

function CompilerError(message) {
	Exception.call(this,message);
}

CompilerError.prototype = new Exception();
